// 注入代码的插件
export function injectGlobalReference() {
  return {
    name: 'inject-global-reference',
    transform(code: string, id: string) {

      // 在这里处理代码转换
      // if (/\.vue$/.test(id)) {
      if (id.includes('/src/views')) {
        if (/\.vue$/.test(id)) {
          // 插入注入的代码
          code = code.replace(`</script>`, `
  import { useRoute, useRouter } from 'vue-router'
  import { ElMessage as $message, ElMessageBox as $messageBox } from 'element-plus'
  const $router = useRouter()
  const $route = useRoute()
          </script>`);
        } else if (id.includes('/hooks') && !id.includes('_form_table')) {
          code = `
          import { ElMessage as $message, ElMessageBox as $messageBox } from 'element-plus'
          ` + code
        }
      }
      return { code };
    },
  };
}